/*
 * Copyright (c) Created by T C L on 2019.7.6.
 * 会员次卡使用记录列表
 */

package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.mumzone.basic.util.AppDateUtil;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.TimeCardEntity;


public class ADA_CardUseRecord extends RecyclerView.Adapter<ADA_CardUseRecord.ViewHolder> {

    private List<TimeCardEntity.TimeCardRecord> dataSet;


    private Context context;
    private boolean isAvailable;//标志是否是可用次卡，改变字体颜色

    public ADA_CardUseRecord(boolean isAvailable) {
        this.isAvailable = isAvailable;
    }

    public void setDataSet(List<TimeCardEntity.TimeCardRecord> dataSet) {
        this.dataSet = dataSet;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        this.context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card_use_record, parent, false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        TimeCardEntity.TimeCardRecord timeCardRecord = dataSet.get(position);

        holder.tvRecordCode.setText(timeCardRecord.getOrderCode());
        holder.tvRecordCount.setText(String.valueOf(timeCardRecord.getUsedNum()));
        holder.tvRecordTime.setText(AppDateUtil.getTimeStamp(timeCardRecord.getCreateTime(),
                AppDateUtil.YYYY_MM_DD_HH_MM));

        if (isAvailable) {
            holder.tvRecordCode.setTextColor(context.getResources().getColor(R.color.content_text_color));
            holder.tvRecordCount.setTextColor(context.getResources().getColor(R.color.content_text_color));
            holder.tvRecordTime.setTextColor(context.getResources().getColor(R.color.content_text_color));
        } else {
            holder.tvRecordCode.setTextColor(context.getResources().getColor(R.color.weak_text_color));
            holder.tvRecordCount.setTextColor(context.getResources().getColor(R.color.weak_text_color));
            holder.tvRecordTime.setTextColor(context.getResources().getColor(R.color.weak_text_color));
        }

    }


    @Override
    public int getItemCount() {
        return dataSet == null ? 0 : dataSet.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_record_code)
        TextView tvRecordCode;
        @BindView(R.id.tv_record_count)
        TextView tvRecordCount;
        @BindView(R.id.tv_record_time)
        TextView tvRecordTime;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}